<!--
 * @Author: 詹真琦(legendryztachi@gmail.com)
 * @Date: 2021-11-04 09:46:23
 * @LastEditors: 詹真琦(legendryztachi@gmail.com)
 * @LastEditTime: 2022-06-06 17:55:57
 * @FilePath: \code\cwp-front\pc-collaboration\src\components\dialog\select-people\index.vue
 * @Description: 选择@的人活着推送的人员
-->
<template>
  <a-modal
    id="select-push-people"
    :title="$i18n('collaboration.pushMessageToMembers.choose')"
    :visible="visible"
    @cancel="$emit('close')"
    @ok="ok"
  >
    <SelectPeopleLocal ref="selectPeopleLocal" :dataList="dataList" />
  </a-modal>
</template>
<script>
  import SelectPeopleLocal from '@/components/atom/select-people-local';
  import { AT_ALL } from '@/plugins/data';
  export default {
    name: 'DialogSelectPeople',
    components: {
      SelectPeopleLocal,
    },
    props: {
      //人员数据列表
      dataList: {
        type: Array,
        default: () => [],
      },
    },
    data() {
      return {
        visible: false,
      };
    },
    mounted() {
      this.visible = true;
    },
    methods: {
      ok() {
        const selectedList = this.$refs.selectPeopleLocal.selectedList;
        console.log('selectPeopleLocal', selectedList);

        // 如果选了所有人就直接艾特all，只有一个人员除外
        this.$emit(
          'selected',
          selectedList.length && selectedList.length === this.dataList.length && this.dataList.length !== 1
            ? AT_ALL.map((d) => d.memberName)
            : selectedList
        );
      },
    },
  };
</script>
<style lang="scss">
  #select-push-people {
    .ant-modal-body {
      padding-top: 10px;
    }

    .ant-modal-footer {
      padding: 10px 24px;
    }
  }
</style>
